
//查询所有供应商报价信息
function checkAllSupplierPrice(){
	var url="";
	$.ajax({
		"type":"POST",
		"url":url,
		"async":false,
		"success":function(){
			var object = $("#bag").html("");
			object.load("allSupplierPrice",function(response,status,xhr){
				//获取客户基本信息
				getClientAll();
				
				var data="name=&currentPages=";
				showSupProduct(data);
			})
		}
	})
	
}

//显示产品信息
function showSupProduct($proData){
		var url="/trade-wzj-web/Supplier_quotaController_Yang/findSupplierQuotaByProductName";
		var tst =postMethod(url,"POST",$proData);
		console.info(tst);
		var ts=tst.list;
		var object =$("#allSupplierApplyPrice tbody").html("");
		//支付状态
		var payStates = "";
		var str="";
		//总价格
		var totalPrice=0.0;
		for(var i=0;i<ts.length;i++){
			var sts=ts[i].productInfoQuota;
			//获取支付状态信息
			var pay = ts[i].paystate;
			for(var a=0;a<pay.length;a++){
				payStates=payStates+
					"<option value="+pay[a].payID+">"+pay[a].payStateName+"</option>";
				
			}
			var k=1;
			for(var j=0;j<sts.length;j++){
				k=i+1;
				//alert(sts[i].productInfoQuotaID);
				console.info(sts[j]);
				str=str+
				
				"<tr>"+
			
					"<td><label>"+
				      "<input type='checkbox' name='productInfoQuotaID' value="+sts[j].productInfoQuotaID+">"+
				    "</label></td>"+
				      							"<td>"+k+"</td>"+
				      							"<td>"+ts[i].supplierInfo.supplierName+"</td>"+
				      							"<td>"+sts[j].productName+"</td>"+
				      							"<td>"+sts[j].productNum+"</td>"+
				      							"<td>"+sts[j].unit+"</td>"+
				      							"<td>"+sts[j].productDelivery+"</td>"+
				      							"<td>"+sts[j].productPrice+"</td >"+
				      							"<td>"+sts[j].rental+"</td>"+
				      							"<td>"+sts[j].expirationDate+"</td>"+
				      							"<td style='text-align:center'><a href='#'><span class='glyphicon glyphicon-pencil'></span></a></td>"+
					"</tr>";
				totalPrice = totalPrice+sts[j].rental;
		}
		}
		
		$("#supplierTotalPrice").html(totalPrice);
		$("#payCondition").html(payStates);
		object.append(str);
		//调用页面显示
		var listPage = getAllProductPage(tst);
		var al = $("#allProducts").html("");
		al.append(listPage);
	}


	//获取页码信息
	function getAllProductPage($clientList){
		var page="";
		
		var con = $("#supProductNames").val();
		page = page+"<div class='row' style='margin:0px'>" +
		"<div class='col-md-2 col-sm-2 col-xs-2' style='padding-top:0.7rem'>"+
			"<span style='font-weight:bold'>总记录数 "+$clientList.total+"   |  总页数 "+$clientList.pages+"</span>"+
		"</div>"+
		"<div class='col-md-offset-8 col-sm-offset-8 col-xs-offset-8'>"
		+"<nav aria-label='Page navigation'>"+
	"<ul class='pagination pagination-sm'>";
		if($clientList.prePage>0){
			page = page+"<li><a href='#' onclick='getPagesSAllProductPrice("+$clientList.firstPage+",\""+con+"\")'>首页</a></li>"+
			"<li><a href='#' onclick='getPagesSAllProductPrice("+$clientList.prePage+",\""+con+"\")'>上一页</a></li>";
					
		}
		if($clientList.nextPage<=$clientList.lastPage && $clientList.nextPage>0){
			page = page+"<li><a href='#' onclick='getPagesSAllProductPrice("+$clientList.nextPage+",\""+con+"\")'>下一页</a></li>"+
			"<li><a href='#' onclick='getPagesSAllProductPrice("+$clientList.lastPage+",\""+con+"\")'>末页</a></li>";
		}
		page = page+"</li>"+
	"</ul>"+
	"</nav>"+
	"</div>"+
	"</div>";
		return page;
		
	}
	
	
	
//点击分页按钮
function getPagesSAllProductPrice($page,$obj){
	var data="name="+$obj+"&currentPages="+$page;
	showSupProduct(data);
}

//点击查询产品功能
function searchSupProduct(){ 
	var con = $("#supProductNames").val();
	var data="productName="+con+"&currentPages=";
	//var url="/trade-wzj-web/Supplier_quotaController_Yang/findSupplierQuotaByProductName";
	showSupProduct(data);
}



//点击全选
function allSelect(){
var list = document.getElementsByName("productInfoQuotaID");
var li = document.getElementsByName("al");
	
	if(li[0].checked){
		for(var i=0;i<list.length;i++){
			list[i].checked=true;
		}
	}else{
		for(var i=0;i<list.length;i++){
			list[i].checked=false;
		}
	}
	var str="";
	for(var i=0;i<list.length;i++){
		if(list[i].checked){
			str=str+list[i].value+",";
		}
		
	}
}

//定义全局集合
var clientPrice="";

//生成客户报价信息
function addClientPriceInfo(){
	var sear=$("#sClientInfo").val();
	var obj=$("#addClientOrderPrice tbody").html("");
	var list = document.getElementsByName("productInfoQuotaID");
	var id=[];
	for(var i=0;i<list.length;i++){
		if(list[i].checked==true){
			id.push(list[i].value);
		}
	}
	if(id.length==0){
		alert("请选择商品");
		return;
	}
	
	var ids=$("#choiceClient").val();
	if(ids==0){
		alert("请选择客户信息");
		return;
	}
	
	//获取条件
	var data="list="+id;
	//获取提交路径
	var url="/trade-wzj-web/Supplier_quotaController_Yang/getListProduct";
	//调用提交方法
	clientPrice = postMethod(url,"POST",data);
	console.info(clientPrice);
	
	if(clientPrice.length>0){
		
		var str="";
		for(var i=0;i<clientPrice.length;i++){
			var ls=clientPrice[i].productInfoQuota;
			for(var j=0;j<ls.length;j++){
				str=str+"<tr>" +
				"<td><input type='hidden' id='productID' name='productInfoQuotaID' value='"+ls[j].productInfoQuotaID+"'> <input type='hidden' class='form-control' name='productName' value='"+ls[j].productName+"'>   <input type='text' readonly='readonyl' class='form-control' value='"+ls[j].productName+"'></td>" +
				"<td><input type='text' class='form-control' onchange='changeNum("+ls[j].productInfoQuotaID+")' id='productNum' name='productNum' value='"+ls[j].productNum+"'></td>" +
				"<td><input type='text' class='form-control' readonly='readonly' id='' name='' value='"+ls[j].unit+"'></td>" +
				"<td><input type='text' class='form-control' name='' value='"+ls[j].expirationDate+"'></td>" +
				"<td><input type='text' class='form-control' id='quotaPrice' name='quotaPrice' value='"+ls[j].productPrice+"'></td>" +
				"<td><input type='text' class='form-control' id='quotaMoney' name='quotaMoney' value='"+ls[j].rental+"'></td>" +
				"<td><input type='text' class='form-control' id='expirationDate' name='expirationDate' value='"+ls[j].expirationDate+"'></td>" +
				"<td><a href='#' onclick='removeClientPrice("+ls[j].productInfoQuotaID+")'><span class='glyphicon glyphicon-remove' style='margin-top:0.2rem'></span></a></td>"+
			"</tr>";
			}
			
			
			
		}
		obj.append(str);
	}
	
	$("#updateSupplierPriceDetailModal").modal("show");
}


//产品数量发生改变时，其金额相应改变
function changeNum($id){
if(clientPrice.length>0){
		
		var str="";
		for(var i=0;i<clientPrice.length;i++){
			var ls=clientPrice[i].productInfoQuota;
			for(var j=0;j<ls.length;j++){
				if($id==ls[j].productInfoQuotaID){
					ls[j].rental
				}
				str=str+"<tr>" +
				"<td><input type='hidden' id='productID' name='productInfoQuotaID' value='"+ls[j].productInfoQuotaID+"'> <input type='hidden' class='form-control' name='productName' value='"+ls[j].productName+"'>   <input type='text' readonly='readonyl' class='form-control' value='"+ls[j].productName+"'></td>" +
				"<td><input type='text' class='form-control' onchange='changeNum("+ls[j].productInfoQuotaID+")' id='productNum' name='productNum' value='"+ls[j].productNum+"'></td>" +
				"<td><input type='text' class='form-control' readonly='readonly' id='' name='' value='"+ls[j].unit+"'></td>" +
				"<td><input type='text' class='form-control' name='' value='"+ls[j].expirationDate+"'></td>" +
				"<td><input type='text' class='form-control' id='quotaPrice' name='quotaPrice' value='"+ls[j].productPrice+"'></td>" +
				"<td><input type='text' class='form-control' id='quotaMoney' name='quotaMoney' value='"+ls[j].rental+"'></td>" +
				"<td><input type='text' class='form-control' id='expirationDate' name='expirationDate' value='"+ls[j].expirationDate+"'></td>" +
				"<td><a href='#' onclick='removeClientPrice("+ls[j].productInfoQuotaID+")'><span class='glyphicon glyphicon-remove' style='margin-top:0.2rem'></span></a></td>"+
			"</tr>";
			}
			
			
			
		}
		obj.append(str);
	}


}




//删除报价信息
function removeClientPrice($productId){
	for(var i=0;i<clientPrice.length;i++){
		var l=clientPrice[i].productInfoQuota;
		for(var j=0;j<l.length;j++){
			if($productId==l[j].productInfoQuotaID){
				l.splice(j,1);
			}
		}
	}
	
	
	var str="";
	for(var i=0;i<clientPrice.length;i++){
		var ls=clientPrice[i].productInfoQuota;
		for(var j=0;j<ls.length;j++){
			str=str+"<tr>" +
			"<td><input type='hidden' id='productID' name='productInfoQuotaID' value='"+ls[j].productInfoQuotaID+"'> <input type='hidden' class='form-control' name='productName' value='"+ls[j].productName+"'>   <input type='text' readonly='readonyl' class='form-control' value='"+ls[j].productName+"'></td>" +
			"<td><input type='text' class='form-control' id='productNum' name='productNum' value='"+ls[j].productNum+"'></td>" +
			"<td><input type='text' class='form-control' readonly='readonly' id='' name='' value='"+ls[j].unit+"'></td>" +
			"<td><input type='text' class='form-control' name='' value='"+ls[j].expirationDate+"'></td>" +
			"<td><input type='text' class='form-control' id='quotaPrice' name='quotaPrice' value='"+ls[j].productPrice+"'></td>" +
			"<td><input type='text' class='form-control' id='quotaMoney' name='quotaMoney' value='"+ls[j].rental+"'></td>" +
			"<td><input type='text' class='form-control' id='expirationDate' name='expirationDate' value='"+ls[j].expirationDate+"'></td>" +
			"<td><a href='#' onclick='removeClientPrice("+ls[j].productInfoQuotaID+")'><span class='glyphicon glyphicon-remove' style='margin-top:0.2rem'></span></a></td>"+
		"</tr>";
		}
		
		
		
	}
	var obj=$("#addClientOrderPrice tbody").html("");
	obj.append(str);
}



//确定添加客户报价信息
function addClientPrices(){
	var addClientForm = $("#addClientPriceForm").Validform({
		tiptype:1
	});
	
	var bool = addClientForm.check();
	if(!bool){
		$("#addClientPriceBtn").popover("toggle");
		return;
	}
	
	for(var i=0;i<clientPrice.length;i++){
		var ls=clientPrice[i].productInfoQuota;
		if(ls.length==0){
			alert("请重新选择信息!");
			return;
		}
	}
	var ids=$("#choiceClient").val();
	var data="clientId="+ids;
		data = data+"&"+$("#addClientPriceForm").serialize();
	
	var url="/trade-wzj-web/tests/kfbjAdd";
	
	var result = postMethod(url,"POST",data);
	if(result){
		alert("操作成功!");
	}else{
		alert("操作失败");
	}
	$("#updateSupplierPriceDetailModal").modal("hide");
}